package com.ysh.spring.mybatis.service.impl;

import com.ysh.spring.mybatis.mapper.DepartmentMapper;
import com.ysh.spring.mybatis.pojo.TDepartments;
import com.ysh.spring.mybatis.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.Random;

/**
 * 袁胜虎 on 2022/8/29 11:38
 */
@Service
@Transactional//开启事务管理 全部使用默认值
public class DepartmentServiceImpl implements DepartmentService {
    private DepartmentMapper departmentMapper;

    @Autowired//自动设置属性
    public void setDepartmentMapper(DepartmentMapper departmentMapper){
        this.departmentMapper = departmentMapper;
    }
    @Override
    @Transactional(propagation = Propagation.SUPPORTS,readOnly = true)//单独给方法设置,优先级高于类上面的
    public TDepartments findBId(long id) {
        return departmentMapper.findBId(id);
    }

    @Override
    public int addDepartment(TDepartments tDepartments) {

        int result = departmentMapper.addDepartment(tDepartments);
        if (new Random().nextBoolean()){
            int i = 1 / 0;
        }
        return result;
    }
}
